/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sudolink.isp.ui;

import com.sudolink.cryptodata.CryptInfoBundle;
import com.sudolink.cryptodata.ISecureData;
import com.sudolink.isp.app.Application;
import com.sudolink.isp.cryptodata.SecureDataHelpers;
import com.sudolink.isp.media.HelperMethods;
import com.sudolink.isp.media.ResourceConstants;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author matsu
 */
public class SecureDataTableModel extends AbstractTableModel {

    private ISecureData[] elements;

    public SecureDataTableModel(ISecureData[] list) {
        elements = list;
    }
    
    @Override
    public int getRowCount() {
        return elements.length;
    }

    @Override
    public int getColumnCount() {
        return 3;
    }

    @Override
    public String getColumnName(int columnIndex) {
        String colName = "";
        switch (columnIndex) {
            case 0:
                colName = "";
                break;
            case 1:
                colName = "Entry Name";
                break;
            case 2:
                colName = "Url";
                break;
        }

        return colName;
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        if (columnIndex == 0) {
            return HelperMethods.getIconResource(ResourceConstants.WORLD_ICON).getClass();
        }

        return "".getClass();
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Object value = null;
        CryptInfoBundle bundle = Application.getPrivateKeys();
        switch (columnIndex) {
            case -1:
                value = elements[rowIndex];
                break;
            case 0:
                ISecureData d = elements[rowIndex];
                if (SecureDataHelpers.isPasswordExpired(d)) {
                    value = HelperMethods.getIconResource(ResourceConstants.EMBLEM_IMPORTANT);
                }
                break;
            case 1:
                value = elements[rowIndex].get(ISecureData.ENTRYNAME, bundle);
                break;
            case 2:
                value = elements[rowIndex].get(ISecureData.URL, bundle);
                break;
        }

        return value;
    }



    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
//        CryptInfoBundle bundle = Application.getPrivateKeys();
//        String value = "";
//        switch( columnIndex ){
//            case 0:
//                value = mgr.getAll()[rowIndex].getName();
//                break;
//            case 1:
//                value = mgr.getAll()[rowIndex].get(ISecureData.URL, bundle);    
//                break;
//            default:
//                value = "Unknown";
//                
//        }
    }

    @Override
    public void addTableModelListener(TableModelListener l) {
    }

    @Override
    public void removeTableModelListener(TableModelListener l) {
    }
}
